﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Inventory.DAL;

namespace Inventory.Test
{
    [TestClass]
    public class CompanyTest
    {
        public int CompanyID { get; set; }

        [TestMethod]
        public void CompanyInsertTest()
        {
            var entities = new InventoryEntities();
            var company = new Company();
            company.Address = "UnitTest Address";
            company.City = entities.City.Where(i => i.ID == 1).First();
            //company.Code = "UnitTest Code"; code has change to be serial
            company.Country = entities.Country.Where(i => i.ID == 1).First();
            company.Currency = entities.Currency.Where(i => i.ID == 1).First();
            company.Name = "UnitTest Company";
            company.Phone = "0253300008";
            company.Website = "http://www.google.com";

            entities.AddToCompany(company);

            company.Lock();
            company.GenerateCode();

            entities.SaveChanges();

            company.ReleaseLock();

            CompanyID = company.ID;

            Assert.IsTrue(company.ID > 0);
            
        }

        [TestMethod]
        public void CompanyDeleteTest()
        {
            int companyID = CompanyID;

            var entities = new InventoryEntities();
            var company = entities.Company.Where(i => i.ID == companyID).First();
            entities.DeleteObject(company);
            entities.SaveChanges();

            var company2 = entities.Company.Where(i => i.ID == companyID).FirstOrDefault();
            Assert.IsNull(company2);
        }
    }
}
